<template>
  <view class="set-page">
    <view class="content">
      <template v-if="isExpert">
        <view class="nav" v-for="item,index in expertList" :key="index" @click="toAppraisal(item.id)">
          <view class="nav-title">{{item.name}}</view>
          <view class="nav-label">
            <view class="nav-version" v-show="item.id ==1">设置鉴定藏品价格</view>
            <up-icon name="arrow-right"></up-icon>
          </view>
        </view>
      </template>
      <view class="nav" v-for="item,index in setList" :key="item.id" @click="onSet(item.id)">
        <view class="nav-title">{{item.name}}</view>
        <view class="nav-label">
          <view class="nav-version" v-if="item.id ==1">{{version}}</view>
          <up-icon name="arrow-right"></up-icon>
        </view>
      </view>
    </view>
  </view>
  <uploadCode :show.sync="uploadShow" :src.sync="src" :title.sync="uploadtitle" :type="uploadType"
    @uploadClose="onUploadClose" @uploadDetail="onUploadDetail" @uploadResolve="onUploadResolve">
  </uploadCode>
</template>

<script setup>
  import {
    ref
  } from 'vue'
  import {
    onLoad
  } from "@dcloudio/uni-app"
  import uploadCode from './components/upload-code/index.vue'
  const version = ref('')
  const isExpert = ref(false)
  const uploadShow = ref(false)
  const uploadtitle = ref('')
  const uploadType = ref('')
  const src = ref('')
  const setList = ref([{
    name: "版本更新",
    id: 1
  }, {
    name: "用户协议",
    id: 2
  }, {
    name: "隐私政策",
    id: 3
  }, {
    name: "关于我们",
    id: 4
  }])
  const expertList = ref([{
    name: "鉴定价格",
    id: 1
  }, {
    name: "启动页图片",
    id: 2
  }, {
    name: "首页广告图",
    id: 3
  }])
  onLoad(() => {
    const systemInfo = uni.getSystemInfoSync()
    version.value = 'V' + systemInfo.appVersion
    isExpert.value = uni.getStorageSync('user').is_expert === 1 ? true : false
  })

  function onSet(id) {
    if (id == 1) {

    } else if (id == 2) {
      uni.navigateTo({
        url: '/pages/my/agreementPage/agreementUser'
      })
    } else if (id == 3) {
      uni.navigateTo({
        url: '/pages/my/agreementPage/agreementPrivacy'
      })
    } else {
      uni.navigateTo({
        url: '/pages/my/agreementPage/aboutPage'
      })
    }
  }

  function toAppraisal(id) {
    if (id == 1) {
      uni.navigateTo({
        url: '/pages/my/otherFunctionPage/appraisalPrice'
      })
    } else if (id == 2) {
      src.value = uni.getStorageSync('atlas').startup_image ? uni.getStorageSync('atlas').startup_image :
        'https://ttj.geiqiutiyu.com/uploads/20241112/145fff0bcffecca8652c6c456a5209c5.png'
      uploadShow.value = true
      uploadtitle.value = "上传启动页图片"
      uploadType.value = id
    } else if (id == 3) {
      src.value = uni.getStorageSync('atlas').banner_image ? uni.getStorageSync('atlas').banner_image :
        "https://tiantianjian.oss-cn-hangzhou.aliyuncs.com/uploads/20241119/40b4bd59653abc99d392821de9bf68ce.png"
      uploadShow.value = true
      uploadtitle.value = "上传首页广告图"
      uploadType.value = id
    }
  }

  function onUploadClose(val) {
    uploadShow.value = val
    src.value = ''
  }

  function onUploadDetail(val) {
    src.value = ''
  }
  function onUploadResolve(val){
    src.value = val
  }
</script>

<style lang="scss" scoped>
  .set-page {
    height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    padding: 30rpx;

    .content {
      width: 100%;
      opacity: 1;
      border-radius: 16rpx;
      background: #FFFFFF;
      box-sizing: border-box;
      padding: 0 30rpx;

      .nav {
        width: 100%;
        height: 88rpx;
        opacity: 1;
        display: flex;
        align-items: center;
        justify-content: space-between;

        .nav-title {
          font-size: 28rpx;
          font-weight: 400;
          color: rgba(51, 51, 51, 1);

        }

        .nav-label {
          display: flex;
          align-items: center;

          .nav-version {
            font-size: 28rpx;
            font-weight: 400;
            color: rgba(153, 153, 153, 1);
            margin-right: 16rpx;
          }
        }
      }
    }
  }
</style>